import CNN
import torch
from DATASET import datasetting
from torch.autograd import Variable
from tool import rightness

_,_,test_loader=datasetting()

cnn=CNN.ConvNet()
cnn_completed=torch.load('checkpoint/minst_conv_checkpoint')

cnn_completed.eval()
rights = []

for data, target in test_loader:
    data, target = Variable(data), Variable(target)

    data = data.cuda()
    target = target.cuda()

    output = cnn_completed(data)
    right = rightness(output, target)
    rights.append(right)

rightsr = (sum([tup[0] for tup in rights]), sum([tup[1] for tup in rights]))
rightrate = 100 *torch.true_divide(rightsr[0] , rightsr[1]) #rightsr[0]/rightsr[1]
print('测试准确率:{:.4f}%'.format(rightrate))



